package com.zhou.framework.filter;

import com.zhou.framework.config.SystemConfig;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CrossOriginFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if(SystemConfig.getInstance().isCrossOrigin()){
            HttpServletResponse r = (HttpServletResponse) response;
            r.addHeader("Access-Control-Allow-Origin","*");
            r.setHeader("Access-Control-Allow-Header", "*");
            r.setHeader("Access-Control-Allow-Methods", "*");
            r.setHeader("Access-Control-Max-Age", "3600");
        }
        chain.doFilter(request, response);
    }
}
